<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../assets/font/iconfont.css">
    <style>
          .rate-box{
            font-size: 12px;
            display: flex;
            flex-flow: row nowrap;
            align-items: center;
        }
        .stars{
            position: relative;
        }
        .stars .iconfont{
            font-size: 1em;
            padding-right: 0.2em;
            cursor: pointer;
            color: #cfcfcf;
        }
        .stars .iconfont.active{
            color: goldenrod;
        }
        .stars .open-stars{
            position: absolute;
            top: 0px;
            left: 0px;
            overflow: hidden;
            pointer-events: none;
            transition: all 500ms ease;
        }
        .source{
            padding-left: 0.5em;
            font-size: 1.1em;
            color: #6f6f6f;
        }
    </style>
</head>
<body>
    <div id="app">
        <my-star v-for="(source,i) in sources" v-model="sources[i]"></my-star>
        
    </div>
    <script type="text/x-template" id="mystar">
        <div class="rate-box">
            <div class="stars">
                <i v-for="c in 5" 
                class="iconfont icon-collection-b"
                :class="{active:modelValue>=c}"
                @click="chooseSource(c*2)"
                ></i>
            </div>
            <div class="source">{{modelValue.toFixed(1)}}</div>
        </div>
    </script>
    <script type="module">
        import { createApp } from "../assets/vue3/vue.esm-browser.js";
        const MyStar={
            template:"#mystar",
            emits:["update: modelValue"],
            props:{
                size:{
                    type:Number,
                    default:12
                },
                modelValue:{
                    type:Number,
                    default:3
                }

            },
            methods:{
                chooseSource(e){
                    this.$emit("update:modelValue",e)
                }
            }
        }
        createApp({
            data() {
                return {
                   sources: [0, 10, 5, 6.8, 3.46, 7.21],
                   size:12
                }
            },
            components:{
             MyStar   
            }
        }).mount("#app");
    </script>
</body>
</html>